﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChessTest.Chess.Items
{
    [Serializable]
    class ElephantsItem : Chessman
    {
        public override string DisplayName =>IsBlack?                     "相": "象";


        public override bool CanOriginMove(Chessboard chessboard,int selectX, int selectY)
        {
            if (!base.CanOriginMove(chessboard,selectX, selectY)) return false;

            if (Math.Abs(selectX - PositionX) != 2 || Math.Abs(selectY - PositionY) != 2)
                return false;

            if (chessboard.GetChessman((PositionX + selectX) / 2, (PositionY + selectY) / 2) != null)
                return false;

            return true;
        }

        protected override bool IsOverstep(Chessboard chessboard,int x, int y)
        {
            if (x < 0 || x >= chessboard.MaxX)
                return true;
            if (PositionY >= 5)
            {
                if (y < 5 || y>= chessboard.MaxY)
                return true;
                
            }
            else if (PositionY < 5)
            {
                if (y < 0 || y>5)
                    return true;
            }

            return false;
        }



        public override List<Point> GetOriginCanMoveList(Chessboard chessboard)
        {
            List<Point> list = new List<Point>();
            if (CanOriginMove(chessboard,PositionX + 2, PositionY + 2))
                list.Add(new Point(PositionX + 2, PositionY + 2));


            if (CanOriginMove(chessboard,PositionX + 2, PositionY - 2))
                list.Add(new Point(PositionX + 2, PositionY - 2));

            if (CanOriginMove(chessboard,PositionX - 2, PositionY + 2))
                list.Add(new Point(PositionX - 2, PositionY + 2));


            if (CanOriginMove(chessboard,PositionX - 2, PositionY - 2))
                list.Add(new Point(PositionX - 2, PositionY - 2));

            return list;
        }
        public override int Score=> 2;
 
    }
}
